<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            :async="true"
            :title="popupTitle"
            width="550px"
            @close="handleClose"
            @confirm="handleClose"
        >
            <el-form ref="formRef" :model="formData" :rules="formRules" disabled label-width="90px">
                <el-form-item label="订单号" prop="sn">
                    <el-input v-model="formData.sn" clearable placeholder="请输入" />
                </el-form-item>
                <el-form-item label="账号类型" prop="account_type">
                    <el-tag v-if="formData.account_type=='agent'">代理商</el-tag>
                    <el-tag v-if="formData.account_type=='dealer'">经销商</el-tag>
                    <el-tag v-if="formData.account_type=='share'">分账人</el-tag>
                </el-form-item>
                <el-form-item label="提现金额" prop="money">
                    <el-input v-model="formData.money" clearable placeholder="请输入提现金额" />
                </el-form-item>
                <el-form-item label="提现状态" prop="status">
                    <el-tag v-if="formData.status==1" type="info">已发起</el-tag>
                    <el-tag v-if="formData.status==2" type="success">成功</el-tag>
                    <el-tag v-if="formData.status==3" type="danger">失败</el-tag>
                </el-form-item>
                <el-form-item label="发起时间" prop="req_time">
                    <el-input v-model="formData.req_time" clearable placeholder="请输入发起时间" />
                </el-form-item>
                <el-form-item label="到账时间" prop="into_time">
                    <el-input v-model="formData.into_time" clearable placeholder="请输入到账时间" />
                </el-form-item>
                <el-form-item label="失败原因" prop="fail_response">
                    <el-input v-model="formData.fail_response" clearable placeholder="请输入失败原因" />
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>

<script lang="ts" name="boomWithdrawEdit" setup>
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiBoomWithdrawDetail } from '@/api/boom_withdraw'
import type { PropType } from 'vue'

defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')


// 弹窗标题
const popupTitle = computed(() => {
    return mode.value == 'edit' ? '编辑提现记录表' : '详情'
})

// 表单数据
const formData = reactive({
    id: '',
    sn: '',
    account_type: '',
    account_id: '',
    money: '',
    status: '',
    req_time: '',
    into_time: '',
    fail_response: '',
    transfer_bill_no: ''
})


// 获取详情
const setFormData = async (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }


}

const getDetail = async (row: Record<string, any>) => {
    const data = await apiBoomWithdrawDetail({
        id: row.id
    })
    setFormData(data)
}


//打开弹窗
const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}

// 关闭回调
const handleClose = () => {
    emit('close')
}


defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
